/*
 * PlusFunction.h
 *
 *  Created on: 20/nov/2010
 *      Author: computer
 */

#ifndef PLUSFUNCTION_H_
#define PLUSFUNCTION_H_
#include "Function.h"
#include "Integer.h"
#include "Real.h"
#include "Rational.h"
#include "Pattern.h"

class IIPlusSimplify {
public:
	TreeExpression::Integer* operator()(TreeExpression::Integer* a, TreeExpression::Integer* b) const {
		return new TreeExpression::Integer(a->getData()+b->getData());
	}
};

class FIPlusSimplify {
public:
	TreeExpression::Real* operator()(TreeExpression::Real* a, TreeExpression::Integer* b) const {
		return new TreeExpression::Real(a->getData()+b->getData());
	}
};

class IFPlusSimplify {
public:
	TreeExpression::Real* operator()(TreeExpression::Integer* a, TreeExpression::Real* b) const {
		return new TreeExpression::Real(a->getData()+b->getData());
	}
};

class FFPlusSimplify {
public:
	TreeExpression::Real* operator()(TreeExpression::Real* a, TreeExpression::Real* b) const {
		return new TreeExpression::Real(a->getData()+b->getData());
	}
};

class RRPlusSimplify {
public:
	TreeExpression::Rational* operator()(TreeExpression::Rational* a, TreeExpression::Rational* b) const {
		return new TreeExpression::Rational(a->getNumerator()*b->getDenominator() + b->getNumerator()*a->getDenominator(), a->getDenominator()*b->getDenominator());
	}
};

class RFPlusSimplify {
public:
	TreeExpression::Real* operator()(TreeExpression::Rational* a, TreeExpression::Real* b) const {
		return new TreeExpression::Real(a->getNumerator()/(double)a->getDenominator()+b->getData());
	}
};

class RIPlusSimplify {
public:
	TreeExpression::Rational* operator()(TreeExpression::Rational* a, TreeExpression::Integer* b) const {
		return new TreeExpression::Rational(a->getNumerator()+b->getData()*a->getDenominator(),a->getDenominator());
	}
};

class IRPlusSimplify {
public:
	TreeExpression::Rational* operator()(TreeExpression::Integer* a, TreeExpression::Rational* b) const {
		return new TreeExpression::Rational(b->getNumerator()+a->getData()*b->getDenominator(),b->getDenominator());
	}
};

class FRPlusSimplify {
public:
	TreeExpression::Real* operator()(TreeExpression::Real* a, TreeExpression::Rational* b) const {
		return new TreeExpression::Real(a->getData()+b->getNumerator()/(double)b->getDenominator());
	}
};

#endif /* PLUSFUNCTION_H_ */
